package com.study.seckill.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 创建切面
 * @author ws
 */
@Aspect
@Component
@Slf4j
public class AopConfig {

    /**
     * 创建切入点：execution表达式指定针对某个（些）方法，进行切入
     */
    @Pointcut("execution(* com.study.seckill.service.CourseSeckillOrderService.addOrder(..))")
    public void addOrder() {}

    @Pointcut("execution(* com.study.seckill.service.CourseSeckillOrderService.updateOrderStatus(..))")
    public void updateOrderStatus() {}

    /**
     * 环绕通知：最先执行，在执行proceed()之前执行前置通知，在return之后执行后置通知
     *
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    @Around("addOrder()")
    public Object aroundAdd(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("此次添加订单的参数是：{}"+joinPoint.getArgs());
        Object obj= (Object) joinPoint.proceed();
       log.info("joinPoint:{}"+joinPoint);
        return obj;
    }
    @Around("updateOrderStatus()")
    public Object aroundUpdate(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("此次添加订单的参数是：{}"+joinPoint.getArgs());
        Object obj= (Object) joinPoint.proceed();
        log.info("joinPoint:{}"+joinPoint);
        return obj;
    }

}